var t = require("../../0E8B0BC42FB173BF68ED63C34BB4DCA6.js"), e = require("../../30A2BE152FB173BF56C4D61233F4DCA6.js"), a = require("../../A7DBB9B62FB173BFC1BDD1B19505DCA6.js");

getApp(), Page({
    data: {
        isx: /iphone10|iphone x/i.test(wx.getSystemInfoSync().model),
        isAndroid: /android/i.test(wx.getSystemInfoSync().system),
        audioSrc: "/mp3/dice1.mp3",
        shakeStatus: "none",
        shaiziShow: "none",
        gaiziShow: "show",
        lidStatus: "close",
        diceAll: [],
        diceResult: [],
        diceStyle: {},
        styleName: "",
        shaiziNums: 5,
        checkedNumber: 6,
        lidAnimation: {},
        cupAnimation: {},
        gaiziAnimate: {},
        selectedNumShow: !0,
        countNum: 0,
        headerTitle: "",
        openSetting: !1,
        currentPages: 1
    },
    onLoad: function(t) {
        this.setData({
            currentPages: getCurrentPages().length
        }), console.log(t);
        var e = t.style, a = getApp().globalData.diceStyles;
        if (e) {
            for (var i = 0; i < a.length; i++) {
                var n = a[i];
                n.tag === e ? (this.setData({
                    diceStyle: n,
                    shaiziNums: n.nums
                }), n.selected = "yes") : n.selected = "";
            }
            getApp().globalData.diceStyles = a, wx.setStorageSync("diceStyles", a);
        }
    },
    onReady: function() {
        var t = this, e = wx.createInnerAudioContext();
        e.autoplay = !1, e.src = this.data.audioSrc, t.audioCtx = e, wx.onAccelerometerChange(function(e) {
            e.x > .8 && "none" === t.data.shakeStatus && (console.log("能摇动"), t.shakeClick());
        });
    },
    onShow: function() {
        this.init();
    },
    onHide: function() {
        this.onBreakDice();
    },
    onUnload: function() {
        this.onBreakDice();
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onBreakDice: function() {
        console.log("onBreakDice..."), this.audioCtx.stop();
    },
    init: function() {
        for (var t = getApp().globalData.diceStyles, e = 0; e < t.length; e++) {
            var a = t[e];
            if ("yes" === a.selected) {
                this.setData({
                    diceStyle: a,
                    shaiziNums: a.nums
                });
                break;
            }
        }
        this.data.diceStyle || this.setData({
            diceStyle: t[0],
            shaiziNums: t[0].nums
        });
        for (var i = this.data.diceAll, n = -1; n <= 1; n++) for (e = 0; e < 6; e++) if (0 != e && 5 != e) {
            var s = {
                imageUrl: "/images/shaizi/dice1_01.png",
                isShow: "hidden",
                imageTop: 200,
                imageLeft: 120
            };
            -1 == n ? (s.imageLeft = 120 + 80 * e, s.imageTop = 200 + 70 * n + 10 * e + 10, 
            i.push(s)) : 1 == n ? (s.imageLeft = 120 + 80 * e, s.imageTop = 200 + 70 * n + 10 * e + 10, 
            i.push(s)) : 0 == n && (s.imageLeft = 100 + 80 * e, s.imageTop = 200 + 70 * n + 10 * e + 10, 
            i.push(s));
        }
        this.setData({
            shakeStatus: "none",
            lidStatus: "close",
            diceAll: i
        }), this.randomDice();
    },
    shakeClick: function() {
        this.setData({
            shakeStatus: "done",
            lidStatus: "close"
        });
        var t = this;
        wx.vibrateLong(), this.audioCtx.stop(), this.audioCtx.seek(0), this.audioCtx.play(), 
        this.randomDice(), setTimeout(function() {
            t.audioCtx.pause();
        }, 1700);
        var e = wx.createAnimation({
            duration: 100,
            timingFunction: "linear"
        });
        e.translate(-5).step(), e.translate(5).step(), e.translate(-5).step(), e.translate(5).step(), 
        e.translate(-5).step(), e.translate(5).step(), e.translate(-5).step(), e.translate(5).step(), 
        e.translate(0).step(), this.lidAnimation = e;
        var a = wx.createAnimation({
            duration: 100,
            timingFunction: "linear"
        });
        this.cupAnimation = a, a.translate(-5).step(), a.translate(5).step(), a.translate(-5).step(), 
        a.translate(5).step(), a.translate(-5).step(), a.translate(5).step(), a.translate(-5).step(), 
        a.translate(5).step(), a.translate(0).step(), this.setData({
            lidAnimation: e.export(),
            cupAnimation: a.export()
        });
    },
    randomDice: function() {
        for (var t = this.data.diceAll, e = 0; e < t.length; e++) t[e].isShow = "hidden";
        for (var a = []; a.length < this.data.shaiziNums; ) {
            var i = Math.floor(12 * Math.random());
            -1 == a.indexOf(i) && a.push(i);
        }
        var n = 0;
        for (e = 0; e < a.length; e++) {
            i = Math.floor(8 * Math.random()) + 1;
            var s = Math.floor(6 * Math.random()) + 1, o = "/images/shaizi/dice" + s + "_0" + i + ".png";
            t[a[e]].imageUrl = o, t[a[e]].isShow = "show", n += s;
        }
        this.setData({
            shaiziShow: "show",
            diceResult: t,
            countNum: n
        });
    },
    openLid: function() {
        this.setData({
            lidStatus: "open"
        });
    },
    closeLid: function() {
        this.setData({
            lidStatus: "close"
        });
    },
    onShareAppMessage: function(a) {
        return {
            title: e(t.SHARE.title)[0],
            path: "/pages/index/index",
            imageUrl: "/assets/" + e(t.SHARE.image)[0]
        };
    },
    back: function() {
        a.navigateBack();
    },
    punishment: function() {
        wx.navigateTo({
            url: "/pages/punishment/index"
        });
    },
    changeSetting: function(t) {
        console.log("changeSetting:", t), this.setData({
            openSetting: !1
        }), this.init();
    },
    openSetting: function() {
        console.log("openSetting"), this.setData({
            openSetting: !0
        });
    }
});